18 #include "clock_config.h" 20 #include "fsl_debug_console.h" 23 #include "fsl_common.h" 24 #include "freemaster.h" 25 #include "freemaster_serial_uart.h" 29 #include "Driver_I2C.h" 34 #include "issdk_hal.h" 35 #include "gpio_driver.h" 42 #define FXLS896x_NUM_REGISTERS (FXLS896x_SELF_TEST_CONFIG2 + 1) 43 #define FF_A_FFMT_THS (0x08) 44 #define A_FFMT_COUNT (0x18) 45 #define PL_COUNT (0x15) 46 #define ASLP_COUNTER (0x07) 47 #define ACCEL_2G_SENS (0.000976) 48 #define ACCEL_4G_SENS (0.001953) 49 #define ACCEL_8G_SENS (0.003906) 50 #define ACCEL_16G_SENS (0.007813) 52 #define RAW_ACCEL_DATA_SIZE (6U) 53 #define MAX8BITSTORAGE (255U) 54 #define FXLS896x_DATA_SIZE 6 159 uint8_t read_trigger;
161 uint8_t readall_size;
162 uint8_t readall_trigger;
164 uint8_t trigger_accel_offnoise;
165 uint8_t trigger_selftest;
169 uint16_t freefall_cntr;
170 uint16_t tapdetect_cntr;
171 uint16_t orient_cntr;
172 uint16_t vecmchange_cntr;
174 uint8_t dataready_cntr;
190 uint8_t complete_accel_offnoise;
202 uint8_t complete_selftest;
241 static FMSTR_U8 recBuffer[1024*10];
248 int16_t
XSTP[2]={0,0},
YSTP[2]={0,0},
ZSTP[2]={0,0},
XSTN[2]={0,0},
YSTN[2]={0,0},
ZSTN[2]={0,0};
259 static void init_freemaster_uart(
void);
393 FMSTR_TSA_TABLE_END()
395 FMSTR_TSA_TABLE_LIST_BEGIN()
396 FMSTR_TSA_TABLE(main_table)
397 FMSTR_TSA_TABLE_LIST_END()
410 recBuffCfg.name =
"FXLS896x 3-Axis Accelerometer Data";
443 init_freemaster_uart();
447 if (ARM_DRIVER_OK != status)
453 status = I2Cdrv->PowerControl(ARM_POWER_FULL);
454 if (ARM_DRIVER_OK != status)
460 status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
461 if (ARM_DRIVER_OK != status)
578 if (ARM_DRIVER_OK != status)
587 rawData.
accel[0] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[3] << 8) | registers.
reg_addr[2])));
588 rawData.
accel[1] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[5] << 8) | registers.
reg_addr[4])));
589 rawData.
accel[2] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[7] << 8) | registers.
reg_addr[6])));
599 else if ((regdata & FXLS896x_SENS_CONFIG1_FSR_MASK) == 4)
603 else if ((regdata & FXLS896x_SENS_CONFIG1_FSR_MASK) == 6)
613 registers.
accel[0] = (float) (rawData.
accel[0] * sensitivity);
614 registers.
accel[1] = (float) (rawData.
accel[1] * sensitivity);
615 registers.
accel[2] = (float) (rawData.
accel[2] * sensitivity);
802 offnoiseptr->
offx = 0.0;
803 offnoiseptr->
offy = 0.0;
804 offnoiseptr->
offz = 0.0;
805 offnoiseptr->
rmsx = 0.0;
806 offnoiseptr->
rmsy = 0.0;
807 offnoiseptr->
rmsz = 0.0;
817 static uint16_t cntr=0;
821 static float xx[
N], yy[
N], zz[
N];
822 static float xm[
N], ym[
N], zm[
N];
823 static float xsq[
N], ysq[
N], zsq[
N];
825 static float sumx=0.0;
826 static float sumy=0.0;
827 static float sumz=0.0;
837 am[0]=rawData->
accel[0]*sens;
838 am[1]=rawData->
accel[1]*sens;
839 am[2]=rawData->
accel[2]*sens;
859 offnoiseptr->
offx=0-sumx;
860 offnoiseptr->
offy=0-sumy;
861 offnoiseptr->
offz=1-sumz;
882 offnoiseptr->
rmsx=pow(stdx,0.5);
883 offnoiseptr->
rmsy=pow(stdy,0.5);
884 offnoiseptr->
rmsz=pow(stdz,0.5);
891 sumx = sumy = sumz = 0;
892 stdx = stdy = stdz = 0;
934 if (ARM_DRIVER_OK != status)
940 for(counter=0;counter<1;counter++)
953 if (ARM_DRIVER_OK != status)
964 if (ARM_DRIVER_OK != status)
1004 static void init_freemaster_uart(
void)
1006 uart_config_t config;
1017 UART_GetDefaultConfig(&config);
1018 config.baudRate_Bps = 115200U;
1019 config.enableTx =
false;
1020 config.enableRx =
false;
1025 FMSTR_SerialSetBaseAddress((UART_Type*)BOARD_DEBUG_UART_BASEADDR);
1027 #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR 1034 #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR 1052 #if defined __CORTEX_M && (__CORTEX_M == 4U) This structure defines the fxls896x all registers metadata.
const registerreadlist_t cFxls896xOutputNormal[]
Address of Raw Accel Data in Normal Mode.
uint8_t byte_data[sizeof(sensor_data)]
void accel_off_noise(fxls896x_acceldata_t *rawData, fxls896x_offset_noise_t *offnoiseptr, float sens)
Function to measure accelerometer offset noise.
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
The fxls896x_drv.h file describes the FXLS8964/67AF driver interface and structures.
This defines the sensor specific information for I2C.
#define FXLS896x_SENS_CONFIG2_ANIC_TEMP_EN
#define FXLS896x_SENS_CONFIG1_FSR_4G
enum fxls896x_operation_type fxls896x_operation_type_t
This structure defines the fxls896x host operation type.
registerDeviceInfo_t deviceInfo
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
fxls896x_acceldata_t rawData
#define FXLS896x_SENS_CONFIG3_WAKE_ODR_12_5HZ
const registerwritelist_t cFxls896xSTYP[]
Register settings for Self-Test in Y Axis (Positive polarity).
#define FXLS896x_NUM_REGISTERS
#define FXLS896x_SENS_CONFIG1_ST_POL_POSITIVE
#define BOARD_BootClockRUN
FMSTR_REC_BUFF recBuffCfg
Access structure of the GPIO Driver.
GENERIC_DRIVER_GPIO * pGpioDriver
int32_t FXLS896x_I2C_Initialize(fxls896x_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *whoami)
The interface function to initialize the sensor.
#define __END_WRITE_DATA__
int32_t apply_register_readall(fxls896x_i2c_sensorhandle_t fxls896xDriver)
Function to apply FXLS896x register read-all operation.
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_MASK
#define FXLS896x_SENS_CONFIG1_FSR_16G
fxls896x_allregs_t registers
This structure defines the Read command List.
const registerwritelist_t cFxls896xConfigNormal[]
Defines the register write list to configure FXLS896x in Interrupt mode.
#define I2C_S_SIGNAL_EVENT
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define FXLS896x_SENS_CONFIG1_ST_POL_MASK
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_Z
const registerwritelist_t cFxls896xSTZN[]
Register settings for Self-Test in Z Axis (Negative polarity).
#define FXLS896x_SENS_CONFIG1_ST_POL_NEGATIVE
const registerwritelist_t cFxls896xSTZP[]
Register settings for Self-Test in Z Axis (Positive polarity).
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
int32_t apply_register_read(fxls896x_i2c_sensorhandle_t fxls896xDriver, uint8_t offset, uint8_t *value)
Function to apply FXLS896x register read operation.
#define FXLS896x_SENS_CONFIG1_FSR_MASK
fxls896x_i2c_sensorhandle_t fxls896xDriver
uint8_t trigger_accel_offnoise
#define FXLS896x_INT_EN_DRDY_EN_MASK
void BOARD_InitDebugConsole(void)
int32_t perform_selftest(fxls896x_i2c_sensorhandle_t fxls896xDriver, fxls896x_selftest_t *selftest)
Function to perform FXLS896x self test.
fxls896x_selftest_t selftest
#define BOARD_DEBUG_UART_CLK_FREQ
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_Y
#define FXLS896x_DATA_SIZE
int32_t FXLS896x_I2C_Configure(fxls896x_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
int main(void)
Main function.
int32_t apply_register_write(fxls896x_i2c_sensorhandle_t fxls896xDriver, uint8_t offset, uint8_t value)
Function to apply FXLS896x register write operation.
int32_t FXLS896x_I2C_ReadData(fxls896x_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
void BOARD_DELAY_ms(uint32_t delay_ms)
Function to insert delays.
#define I2C_S_DEVICE_INDEX
This structure defines variables to compute self-test output change (STOC) and self-test offset (STOF...
void(* toggle_pin)(pinID_t aPinId)
uint8_t complete_selftest
#define FXLS896x_SENS_CONFIG2_ANIC_TEMP_MASK
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
gpioHandleKSDK_t GREEN_LED
fxls896x_operation_type
This structure defines the fxls8962 host operation type.
volatile bool bFxls896xIntFlag
void FXLS896x_I2C_SetIdleTask(fxls896x_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
FMSTR_TSA_TABLE_BEGIN(main_table)
Target Side Addressable (TSA) table created for this application.
const registerreadlist_t FXLS896x_ALL_REG_READ[]
FXLS896x register list to read all registers.
void fxls896x_isr_callback(void *pUserData)
ISR for FXLS896x interrupt source event.
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
int32_t Register_I2C_Write(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, uint8_t offset, uint8_t value, uint8_t mask, bool repeatedStart)
The interface function to write a sensor register.
uint8_t reg_addr[FXLS896x_NUM_REGISTERS]
void offset_noise_init(fxls896x_offset_noise_t *offnoiseptr)
Function to initialize offset noise measurement.
void BOARD_SystickEnable(void)
Function to enable systicks framework.
#define FXLS896x_I2C_ADDR
void selftest_init(fxls896x_selftest_t *selftest)
Function to initialize FXLS896x self test metadata.
fxls896x_offset_noise_t offnoise_data
uint8_t complete_accel_offnoise
#define __END_READ_DATA__
This structure defines the Write command List.
#define BOARD_DEBUG_UART_BASEADDR
This structure defines the fxls896x offset and noise calculation parameters.
const registerreadlist_t cFXLS896x_fs_src[]
Prepare the register read for FullScale range Register.
int32_t update_dropdown_selection(fxls896x_allregs_t *registers, uint8_t caller)
Function to update dropdown selection.
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_DISABLED
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_X
This structure defines the fxls896x raw data buffer.
const registerreadlist_t cFXLS896x_whoami[]
#define FXLS896x_INT_EN_DRDY_EN_EN
#define FXLS896x_SENS_CONFIG3_WAKE_ODR_MASK
#define BOARD_UART_IRQ_HANDLER
const registerwritelist_t cFxls896xSTXP[]
Register settings for Self-Test in X Axis (Positive polarity).
uint8_t readall_value[FXLS896x_NUM_REGISTERS]
const registerwritelist_t cFxls896xSTYN[]
Register settings for Self-Test in Y Axis (Negative polarity).
const registerwritelist_t cFxls896xSTXN[]
Register settings for Self-Test in X Axis (Negative polarity).
const registerreadlist_t cFXLS896x_int_src[]
Prepare the register read for INT Status Register.
This structure defines the fxls8962 raw data buffer.